package site.jlopen.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import jakarta.servlet.http.HttpServletRequest;
import site.jlopen.assets.config.ThreadAuthUser;

@Controller
public class RouterController {
	private final Logger log = LoggerFactory.getLogger(getClass());

	@RequestMapping(value= {"/", "/index"})
	public String def() {
		log.info("控制面板");
		return "index";
	}

	/*@RequestMapping("/error")
	public String error() {
		return "common/error";
	}*/

	@RequestMapping("/node")
	public String nodeManage() {
		return "node/manage";
	}

	@RequestMapping("/node/partner")
	public String partnerNode() {
		return "node/partner";
	}

	@RequestMapping("/datasource")
	public String dataSourceManage() {
		return "datasource/manage";
	}

	@RequestMapping("/data")
	public String dataManage() {
		return "data/manage";
	}

	@RequestMapping("/project")
	public String projectManage() {
		return "project/manage";
	}

	@RequestMapping("/project/detail")
	public String projectDetail() {
		return "project/detail";
	}

	@RequestMapping("/result")
	public String resultManage() {
		return "result/manage";
	}

	@RequestMapping("/message")
	public String messageManage() {
		return "message/manage";
	}

	@RequestMapping("/account")
	public String accountManage() {
		return "account/manage";
	}

	@RequestMapping("/log")
	public String log() {
		return "log/manage";
	}

	@RequestMapping("/test")
	public String test() {
		return "test/test";
	}

	@RequestMapping("/dag")
	public String dag() {
		return "test/dag";
	}

	@RequestMapping("/dag2")
	public String dag2() {
		return "test/dag2";
	}

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		return "login";
	}

	@RequestMapping(value = "/register", method = RequestMethod.GET)
	public String register() {
		return "register";
	}

	@RequestMapping("/logout")
	public String logout(HttpServletRequest request) {
		request.getSession().removeAttribute(ThreadAuthUser.USER_SESSION);
		Subject subject = SecurityUtils.getSubject();
        subject.logout();
		return "redirect:/login";
	}
}
